<%@ page pageEncoding="UTF-8"%>

<%@ taglib uri="/tags/struts-tiles" prefix="tiles"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/struts-nested" prefix="nested"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/tags/trymore" prefix="tm"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix='fmt'%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<style>
.logtext {word-wrap:break-word; word-break:break-all; text-align:left;}
.logtext div {overflow:auto; word-wrap: break-word;  text-align:left;}
.logtext {word-wrap:break-word; word-break:break-all; text-align:left;}
.logtext div {overflow:auto; word-wrap: break-word;  text-align:left;}
</style>

<script type="text/javascript">
	function queryLog() {
		// 重新加载当前弹框页面数据
		if ($.pdialog._current != null) {
			var startDate 	= $("#queryStartDate", $.pdialog._current).val();
			var endDate 	= $("#queryEndDate", $.pdialog._current).val();
			var workType 	= $("#queryWorkType", $.pdialog._current).find("option:selected").attr("value");
			$.pdialog.reload("app/worklog.do?action=dialogWorkLogQuery&cat=${cat}&startDate=" + startDate + "&endDate=" + endDate + "&workType=" + workType);
		}
	}
	
	function test(page) {
		alert(page);
	}
	
	$("#export_worklog").click(function(){
		$p = $.pdialog._current;
		$.post("app/worklog.do?action=actionExportWorkLog", {
			"cat"		: "${cat}",
			"startDate"	: $("#queryStartDate", $p).val(),
			"endDate"	: $("#queryEndDate", $p).val(),
			"workType"	: $("#queryWorkType", $p).find("option:selected").attr("value")
		}, function(rsp){
			var feedback = eval('(' + rsp + ')');
			if (feedback.status && feedback.status == 200) 
			{
				var windowAttr = "location=yes,statusbar=no,directories=no,menubar=no,titlebar=no,toolbar=no,dependent=no,resizable=yes,personalbar=no,scrollbars=yes"; 
				window.open("file-download?path="+feedback.file+"&filename="+feedback.name, "_blank",  windowAttr);
			} 
			else 
			{
				// error message migtht be raised here.
				alert(feedback.message);
			}
		});
	});
</script>

<form id="pagerForm" method="post" action="app/worklog.do?action=dialogWorkLogQuery">
	<input type="hidden" name="pageNum" value="${pagingBean ne null ? pagingBean.currentPage : 1}" />
	<input type="hidden" name="numPerPage" value="${pagingBean ne null ? pagingBean.pageSize : 20}" />
	<input type="hidden" name="cat" value="${cat}" />
	<input type="hidden" name="startDate" value="${startDate}" />
	<input type="hidden" name="endDate" value="${endDate}" />
	<input type="hidden" name="workType" value="${workType}" />
	<input type="hidden" name="uid" value="${uid ne null ? uid : -1}" />
</form>

<div class="pageContent">
	<!-- SearchBar -->
	<div class="panelBar" style="padding: 2px 5px;">
		<c:choose>
			<c:when test="${mode ne null && mode eq 'query'}">
				<table style="float:left;overflow:hidden;clear:both;">
					<tr>
						<td>日期查询：</td>
						<td>
							<input class="textInput date" value="${startDate}" 
								name="startDate" type="text" id="queryStartDate" style="margin-top:2px;width:80px;"/>
						</td>
						<td width="20px" align="center">至</td>
						<td>
							<input class="textInput date" value="${endDate}" 
								name="endDate" type="text" id="queryEndDate" style="margin-top:2px;width:80px;"/>
						</td>
						<td style="padding-left: 5px;">工作类型：</td>
						<td>
							<select name="workType" id="queryWorkType" style="margin-top: 2px">
								<option value="">所有</option>
								<logic:present name="dictWorkTypes">
									<logic:iterate name="dictWorkTypes" id="type">
										<option value="${type.id}" ${workType ne null && workType eq type.id ? 'selected' : ''}>${type.dictKey}</option>
									</logic:iterate>
								</logic:present>
							</select>
						</td>
						<td style="padding-left: 8px;"><a class="button" onclick="javascript:queryLog()"><span>日志查询</span></a></td>
					</tr>
				</table>
			</c:when>
			<c:otherwise>
				<table style="float:left;overflow:hidden;clear:both;">
					<tr  style="line-height:25px;">
						<td style="font-weight:bold;line-height:25px;">一周工作日志</td>
						<td style="padding-left: 20px;">姓名：</td>
						<td style="color: #CF0800;">${logOwner ne null ? logOwner.username : ''}</td>
						<td style="padding-left: 20px;">时间：</td>
						<td style="color: #CF0800;">${startDate} ~ ${endDate}</td>
					</tr>
				</table>
			</c:otherwise>
		</c:choose>
		<c:if test="${pagingBean ne null && pagingBean.totalItems gt 0}">
			<ul class="toolBar" style="float:right;">
				<li>
					<a class="icon" title="日志导出" id="export_worklog" href="javascript:void(0);"><span>日志导出</span></a>
				</li>
			</ul>
		</c:if>
	</div>
	
	<!-- DataGrid -->
	<table class="table" width="100%" layoutH="80">
		<thead>
			<tr>
				<th align="center" width="80px">日期</th>
				<th align="center" width="30px">序号</th>
				<th align="center" width="85px">项目编号</th>
				<th align="center">项目名称</th>
				<th align="center">工作类别</th>
				<th align="center">工作事件</th>
			</tr>
		</thead>
		<tbody>
			<logic:present name="logData">
				<logic:iterate id="log" name="logData" indexId="idx">
					<bean:define id="date" property="key" name="log" />
					<bean:define id="logs" property="value" name="log" />
					<tr ${idx % 2 == 1 ? 'style="background-color: #F5F5F5"' : ''}>
						<td rowspan="${fn:length(logData[date])}">${date}</td>
						<c:forEach items="${logs}" var="entity" varStatus="status" end="0">
							<td>${status.index+1}</td>
							<td>${entity.logProject ne null ? entity.logProject.projectNo : 'N/A'}</td>
							<td class="logtext">${entity.logProject ne null ? entity.logProject.projectName : '非工作项目'}</td>
							<td>${entity.logWorkType.dictKey}</td>
							<td class="logtext">${entity.logEvent}</td>
						</c:forEach>
					</tr>
					
					<c:forEach items="${logs}" var="entity" varStatus="status" begin="1">
						<tr ${idx % 2 == 1 ? 'style="background-color: #F5F5F5"' : ''}>
							<td>${status.index+1}</td>
							<td>${entity.logProject ne null ? entity.logProject.projectNo : 'N/A'}</td>
							<td class="logtext">${entity.logProject ne null ? entity.logProject.projectName : '非工作项目'}</td>
							<td>${entity.logWorkType.dictKey}</td>
							<td class="logtext">${entity.logEvent}</td>
						</tr>
					</c:forEach>
				</logic:iterate>
			</logic:present>
		</tbody>
	</table>
	
	<!-- Pagination -->
	<div class="panelBar">
		<div class="pages">
			<span>显示</span>
			<select class="combox" name="numPerPage" onchange="navTabPageBreak({numPerPage:this.value})">
				<option value="20" ${pagingBean ne null && pagingBean.pageSize eq 20 ? 'selected="selected"' : ''}>20</option>
				<option value="50" ${pagingBean ne null && pagingBean.pageSize eq 50 ? 'selected="selected"' : ''}>50</option>
				<option value="100" ${pagingBean ne null && pagingBean.pageSize eq 100 ? 'selected="selected"' : ''}>100</option>
				<option value="200" ${pagingBean ne null && pagingBean.pageSize eq 200 ? 'selected="selected"' : ''}>200</option>
			</select>
			<span>条，共${pagingBean ne null ? pagingBean.totalItems : 0}条</span>
		</div>	
		<div class="pagination" targetType="dialog" totalCount="${pagingBean ne null ? pagingBean.totalItems : 0}" numPerPage="${pagingBean ne null ? pagingBean.pageSize : 20}" pageNumShown="${pagingBean ne null ? pagingBean.pageNumShown : 10}" currentPage="${pagingBean ne null ? pagingBean.currentPage : 1}"></div>
	</div>
</div>